How to Resolve 'List Index Out of Range' Error in Python For Loop Code